﻿using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Sidvall.Security
{
    public static class AuthenticationClientExtension
    {
        #region RequestAuthorizationCodeAsync

        public static async Task<TokenResponse> RequestAuthorizationCodeAsync(this IAuthenticationClient value, string code, string redirectAddress)
        {
            return await RequestAuthorizationCodeAsync(value, code, redirectAddress, null, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestAuthorizationCodeAsync(this IAuthenticationClient value, string code, string redirectAddress, string codeVerifier)
        {
            return await RequestAuthorizationCodeAsync(value, code, redirectAddress, codeVerifier, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestAuthorizationCodeAsync(this IAuthenticationClient value, string code, string redirectAddress, string codeVerifier,
            CancellationToken cancellationToken)
        {
            return await value.RequestAuthorizationCodeAsync(code, redirectAddress, codeVerifier, null, cancellationToken).ConfigureAwait(false);
        }

        public static async Task<TokenResponse> RequestAuthorizationCodeAsync(this IAuthenticationClient value, string code, string redirectAddress, string codeVerifier,
            Dictionary<string, string> additionalValues)
        {
            return await value.RequestAuthorizationCodeAsync(code, redirectAddress, codeVerifier, additionalValues, CancellationToken.None).ConfigureAwait(false);
        }

        #endregion
        #region RequestClientCredentialsAsync

        public static async Task<TokenResponse> RequestClientCredentialsAsync(this IAuthenticationClient value)
        {
            return await RequestClientCredentialsAsync(value, null, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestClientCredentialsAsync(this IAuthenticationClient value, string scope)
        {
            return await RequestClientCredentialsAsync(value, scope, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestClientCredentialsAsync(this IAuthenticationClient value, string scope, CancellationToken cancellationToken)
        {
            return await value.RequestClientCredentialsAsync(scope, null, cancellationToken).ConfigureAwait(false);
        }

        public static async Task<TokenResponse> RequestClientCredentialsAsync(this IAuthenticationClient value, string scope, Dictionary<string, string> additionalValues)
        {
            return await value.RequestClientCredentialsAsync(scope, additionalValues, CancellationToken.None).ConfigureAwait(false);
        }

        #endregion
        #region RequestRefreshTokenAsync

        public static async Task<TokenResponse> RequestRefreshTokenAsync(this IAuthenticationClient value, string refreshToken)
        {
            return await RequestRefreshTokenAsync(value, refreshToken, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestRefreshTokenAsync(this IAuthenticationClient value, string refreshToken,
            CancellationToken cancellationToken)
        {
            return await value.RequestRefreshTokenAsync(refreshToken, null, cancellationToken).ConfigureAwait(false);
        }

        public static async Task<TokenResponse> RequestRefreshTokenAsync(this IAuthenticationClient value, string refreshToken,
            Dictionary<string, string> additionalValues)
        {
            return await value.RequestRefreshTokenAsync(refreshToken, additionalValues, CancellationToken.None).ConfigureAwait(false);
        }

        #endregion
        #region RequestResourceOwnerPasswordAsync

        public static async Task<TokenResponse> RequestResourceOwnerPasswordAsync(this IAuthenticationClient value, string userName, string password)
        {
            return await RequestResourceOwnerPasswordAsync(value, userName, password, null, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestResourceOwnerPasswordAsync(this IAuthenticationClient value, string userName, string password, string scope)
        {
            return await RequestResourceOwnerPasswordAsync(value, userName, password, scope, CancellationToken.None).ConfigureAwait(false);
        }
        public static async Task<TokenResponse> RequestResourceOwnerPasswordAsync(this IAuthenticationClient value, string userName, string password, string scope,
            CancellationToken cancellationToken)
        {
            return await value.RequestResourceOwnerPasswordAsync(userName, password, scope, null, cancellationToken).ConfigureAwait(false);
        }

        public static async Task<TokenResponse> RequestResourceOwnerPasswordAsync(this IAuthenticationClient value, string userName, string password, string scope,
            Dictionary<string, string> additionalValues)
        {
            return await value.RequestResourceOwnerPasswordAsync(userName, password, scope, additionalValues, CancellationToken.None).ConfigureAwait(false);
        }

        #endregion
    }
}
